package com.kaiyiweitong.tongxing.fragment.home_fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridLayout;

import com.kaiyiweitong.tongxing.R;
import com.kaiyiweitong.tongxing.activity.MainActivity;
import com.kaiyiweitong.tongxing.adapter.ServiceListAdapter;

public class ServiceListFragment extends Fragment {

    private static final String ARG_PARAM1 = "param1";

    private String mParam1;
    private View mView;
    private MainActivity mActivity;

    public static ServiceListFragment newInstance(String param1) {
        ServiceListFragment fragment = new ServiceListFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mActivity = (MainActivity) getActivity();
        mView = inflater.inflate(R.layout.fragment_service_list, container, false);
        init();
        return mView;
    }

    private void init() {
        RecyclerView rv = mView.findViewById(R.id.rv_service_list);
        ServiceListAdapter adapter = new ServiceListAdapter(mActivity);
        rv.setLayoutManager(new GridLayoutManager(mActivity, 2, GridLayout.VERTICAL, false));
        rv.setAdapter(adapter);
    }
}
